/*
 *	Copyright (C) 2008 - Mauricio Bieze Stefani
 *	This file is part of the Insano Game Engine.
 *
 *	Insano is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	Insano is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with Insano.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "InputDevices.h"

using namespace irr;
using namespace core;

bool Mouse::handleIrrlicht(const irr::SEvent& event)
{
	if(event.EventType != EET_MOUSE_INPUT_EVENT)
		return false;
	switch(event.MouseInput.Event)
	{
		case EMIE_LMOUSE_PRESSED_DOWN:
			left = true;
			dragstart.X = event.MouseInput.X;
			dragstart.Y = event.MouseInput.Y;
		break;
		case EMIE_RMOUSE_PRESSED_DOWN:
			right = true;
		break;
		case EMIE_MMOUSE_PRESSED_DOWN:
			mid = true;
		break;
		case EMIE_LMOUSE_LEFT_UP:
			left = false;
		break;
		case EMIE_RMOUSE_LEFT_UP:
			right = false;
		break;
		case EMIE_MMOUSE_LEFT_UP:
			mid = false;
		break;
		case EMIE_MOUSE_MOVED:
			pos.X = event.MouseInput.X;
			pos.Y = event.MouseInput.Y;
			if(left)
			{
				drag.X+=(pos.X-dragstart.X);
				drag.Y+=(pos.Y-dragstart.Y);
				dragstart.X=pos.X;
				dragstart.Y=pos.Y;
			}
		break;
		case EMIE_MOUSE_WHEEL:
			wheel+=event.MouseInput.Wheel;
		break;
		default:
		return false;
	}
	return true;
}

Keyboard::Keyboard()
{
	kbdgui=false;
	clear();
}

bool Keyboard::handleIrrlicht(const irr::SEvent& event)
{
	if(event.EventType != EET_KEY_INPUT_EVENT)
		return false;
	if(event.KeyInput.PressedDown)
	{
		status[event.KeyInput.Key]=true;
		hit[event.KeyInput.Key]=true;
	}
	else
		status[event.KeyInput.Key]=false;
	return true;
}

void Keyboard::clear()
{
	for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++)
		hit[x] = status[x] = false;
}
